import { ConfigSvr } from './../../services/config';
import { Component, OnInit } from '@angular/core';
import { AppModel } from "app/models/kdsConfig";

@Component({
    selector: 'expedition-order-setup',
    styleUrls: ['./index.scss'],
    template: `
        <div class="expedition-order-container">
            <ul>
                <li *ngFor="let option of orderSetupOptions" style="display: flex; padding: 0.8rem; border-bottom: 1px solid #999999;" [hidden]="!isValidOrderSetupOptionNames(option.name)">
                    <options  [option]="option"></options>
                </li>
            </ul>
        </div>
    `
})

export class ExpeditionOrderSetup implements OnInit {
    constructor(private configSvr: ConfigSvr) { }

    isValidOrderSetupOptionNames(name) {
        return this.validOrderSetupOptionNames.indexOf(name) > -1;
    }

    get validOrderSetupOptionNames(): Array<string> {
        const appModel = this.configSvr.appConfig.model;
        let options;
        switch (appModel) {
            case AppModel.FastFood:
                options = ["expeditionOrderConfigQRCodePrinted"]
            case AppModel.HotPot:
                options = ["expeditionOrderConfigQRCodePrinted"]
                break;
            default:
                break;
        }
        return options;
    }

    ngOnInit() {
        this.orderSetupOptions.find(option => option.name == "expeditionOrderConfigQRCodePrinted").onChange = (sender: {
            checked: boolean
        }) => {
            const expeditionOrderConfig = this.configSvr.expeditionOrderConfig;
            expeditionOrderConfig.QRCodePrinted = sender.checked;
            this.configSvr.expeditionOrderConfig = expeditionOrderConfig;
        }

    }

    orderSetupOptions = [
        {
            name: "expeditionOrderConfigQRCodePrinted",
            "title": "出品一维码打印",
            "description": "是否打印一维码",
            type: "switch",
            timing: 0,
            checked: this.configSvr.expeditionOrderConfig.QRCodePrinted,
            operation(option) {
                this.checked = !this.checked;
                this.onChange(this);
            },
            onChange: (sender) => { }
        }
    ]
}